package com.xy.mainp.main.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

import com.xy.base.reciver.ExitReciver;
import com.xy.mainp.R;
import com.xy.mainp.base.BasePActivity;
import com.xy.mainp.main.widget.MainCevView;

public class MainActivity extends BasePActivity {


    private MainCevView mainCevView;

    @Override
    protected void initView(Bundle savedInstanceState) {
        mainCevView = new MainCevView(this);
        setContentView(mainCevView);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    public static void enter(Intent intent,Activity activity) {
        intent.setClass(activity, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(intent);
    }

    private long exitTime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return Click2Exit();
        }
        return super.onKeyDown(keyCode, event);
    }

    //再按一次退出程序
    private boolean Click2Exit() {
        if (System.currentTimeMillis() - exitTime >= 2000) {
            showToastMsg(getString(R.string.exit_string));
            exitTime = System.currentTimeMillis();
        } else {
            ExitReciver.exit(this);
        }
        return true;
    }

}
